package com.woniu.controller;

import com.woniu.Result;
import com.woniu.dto.OrderPayDto;
import com.woniu.pojo.Care;
import com.woniu.pojo.vo.CareVo;
import com.woniu.pojo.vo.OrderVo;
import com.woniu.pojo.vo.PaymentVo;
import com.woniu.service.ICareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zbk
 * @since 2022-11-16
 */
@RestController
@RequestMapping("/care")
@Api(tags = "保养")
public class CareController {

    @Autowired
    private ICareService careService;

    @ApiOperation("获取保养项目")
    @GetMapping("/{shopId}")
    public Result<List<Care>> queryAllCare(@PathVariable Integer shopId){
        List<Care> careList = careService.queryAllCare(shopId);
        return Result.ok(careList);
    }

    @ApiOperation("下单")
    @PostMapping("user-auth/submit/{productId}/{shopId}")
    public Result<OrderVo> submitOrder(@PathVariable Integer productId, @PathVariable Integer shopId, HttpServletRequest request ){
         String userId = request.getHeader("userId");
        OrderVo orderVo = careService.submitOrder(productId, userId, shopId);
        return Result.ok(orderVo);
    }

    @ApiOperation("确认订单")
    @PostMapping("user-auth/confirm")
    public Result<PaymentVo> confirmOrder(@RequestBody OrderPayDto orderPayDto, HttpServletRequest request){
         String userId = request.getHeader("userId");
        PaymentVo paymentVo = careService.confirmOrder(orderPayDto, userId);
        return Result.ok(paymentVo);
    }

    @ApiOperation("支付订单")
    @PostMapping("/user-auth/pay")
    public Result<String> payOrder(@RequestBody OrderPayDto orderPayDto, HttpServletRequest request, HttpServletResponse httpResponse){
         String userId = request.getHeader("userId");
        Result<String> result = careService.payOrder(orderPayDto, userId, httpResponse);
        return result;
    }

    @ApiOperation("验证编码")
    @PostMapping("user-auth/verify/{code}")
    public Result<String> verifyCode(@PathVariable String code,HttpServletRequest request ){
        String userId = request.getHeader("userId");
        Result<String> result = careService.verifyCode(code, userId);
        return result;
    }
}
